local jianmo = fk.CreateSkill{
  name = "kl__jianmo",
}

Fk:loadTranslationTable{
  ["kl__jianmo"] = "箭魔",
  [":kl__jianmo"] = "出牌阶段，你可以<a href='#RuMoDesc'><font color='red'>入魔</font></a>，然后令本局所有进入你攻击范围内的角色成为“鬼”角色。",

  ["#kl__jianmo"] = "箭魔：<font color='red'>入魔</font>，然后本局所有进入你攻击范围内的角色成为“鬼”角色！",
  ["@@klmo__huangzhong_gui"] = "<font color='red'>鬼</font>",

  ["$kl__jianmo1"] = "皓首曳白羽，寒光霜天下！",
  ["$kl__jianmo2"] = "青冥断七杀，赤澜缚天狼！",
}

jianmo:addEffect("active", {
  anim_type = "big",
  prompt = "#kl__jianmo",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return not player:hasSkill("#rumo", true)
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    room:setPlayerMark(player, "klmo__jianmo"..player.id, 1)
    room:handleAddLoseSkills(player, "#rumo", nil, false, true)
    local tos = {}
    for _, p in ipairs(room.alive_players) do
      if player:inMyAttackRange(p) then
        table.insert(tos, p)
      end
    end
    room:doIndicate(player, tos)
    for _, p in ipairs(tos) do
      room:setPlayerMark(p, "@@klmo__huangzhong_gui", 1)
    end
  end,
})

local spec = {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(jianmo.name) and player:getMark("klmo__jianmo"..player.id) > 0 then
      local tos = {}
      for _, p in ipairs(player.room.alive_players) do
        if player:inMyAttackRange(p) and p:getMark("@@klmo__huangzhong_gui") == 0 then
          table.insert(tos, p)
        end
      end
      if #tos > 0 then
        event:setCostData(self, { to = tos })
        return true
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local tos = event:getCostData(self).to
    player.room:doIndicate(player, tos)
    for _, p in ipairs(tos) do
      player.room:setPlayerMark(p, "@@klmo__huangzhong_gui", 1)
    end
  end,
}

jianmo:addEffect(fk.AfterCardsMove, spec)
jianmo:addEffect(fk.AfterSkillEffect, spec)


return jianmo
